CSharpTest.Net
ReadFrom Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Serialization Namespace > ISerializer<T> Interface : ReadFrom Method

stream

Glossary Item Box

Reads the object from a stream

Syntax

Visual Basic (Declaration) 
Function ReadFrom( _
   ByVal stream As Stream _
) As T
C# 
T ReadFrom( 
   Stream stream
)

Parameters

stream

Example

Library/Library.Test/TestSegmentedStream.cs

C#Copy Code
using (SharedMemoryStream shared = new SharedMemoryStream())
{
    shared.Position = ushort.MaxValue - 25;
    Assert.AreEqual(ushort.MaxValue - 25, shared.Length);
    Assert.AreEqual(ushort.MaxValue - 25, shared.Position);

    using (Stream copy = ((IFactory<Stream>) shared).Create())
    {
        Assert.AreEqual(0L, copy.Position);//does not clone position of original stream...
        Assert.AreEqual(shared.Length, copy.Length);//does clone length of the stream...
        copy.Position = shared.Position;

        for (int i = 0; i < 100; i++)
        {
            PrimitiveSerializer.Int32.WriteTo(i, shared);
            Assert.AreEqual(i, PrimitiveSerializer.Int32.ReadFrom(copy));
        }
    }
}
VB.NETCopy Code
Using [shared] As New SharedMemoryStream()
    [shared].Position = UShort.MaxValue - 25
    Assert.AreEqual(UShort.MaxValue - 25, [shared].Length)
    Assert.AreEqual(UShort.MaxValue - 25, [shared].Position)

    Using copy As Stream = (DirectCast([shared], IFactory(Of Stream))).Create()
        Assert.AreEqual(0L, copy.Position)
        'does not clone position of original stream...
        Assert.AreEqual([shared].Length, copy.Length)
        'does clone length of the stream...
        copy.Position = [shared].Position

        Dim i As Integer = 0
        While i < 100
            PrimitiveSerializer.Int32.WriteTo(i, [shared])
            Assert.AreEqual(i, PrimitiveSerializer.Int32.ReadFrom(copy))
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys